

package org.itboys.mobile.service.mysql.front;

import org.apache.commons.lang3.StringUtils;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mobile.dao.product.SundayProductCategoryMapper;
import org.itboys.mobile.dto.product.SundayProductBrandDto;
import org.itboys.mobile.entity.mongo.SundayProductCategoryBrand;
import org.itboys.mobile.entity.mysql.product.SundayProductBrand;
import org.itboys.mobile.service.mongo.SundayProductCategoryBrandService;
import org.itboys.mysql.service.BaseMySqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_商品_品牌_service_mobile
 */


@Service
public class SundayFrontProductBrandService extends BaseMySqlService<SundayProductBrand> {
    @Autowired
    private SundayProductCategoryBrandService categoryBrandService;
    @Autowired
    private ResourceHolder resourceHolder;
    /**
     * 不分页获取品牌信息
     * @param firstCatId
     * @param secondCatId
     * @param name
     */
    public List<SundayProductBrandDto> getBrands(Long firstCatId,Long secondCatId,String name,Integer isHaiTao){
        Map<String,Object> param = new HashMap<String,Object>();
        List<Long> brandIds=categoryBrandService.getByCategoryId(firstCatId,secondCatId);
        param.put("ids",brandIds);
        if(StringUtils.isNotEmpty(name)){
            param.put("name",name);
        }
        return packageBatch(super.select(param));
     }
    public SundayProductBrandDto packageSingle(SundayProductBrand productBrand){
        return new SundayProductBrandDto(productBrand.getId(), productBrand.getCreateTime(), productBrand.getCreateDate(),
                resourceHolder.getStringValue("imgRoot")+productBrand.getImage(), productBrand.getName());
    }
    public List<SundayProductBrandDto> packageBatch(List<SundayProductBrand> productBrands){
        List<SundayProductBrandDto> dtos = new ArrayList<SundayProductBrandDto>();
        for(SundayProductBrand productBrand:productBrands){
            dtos.add(packageSingle(productBrand));
        }
        return  dtos;
    }
  }






